#pragma once

#include <QtCore/QVector>
#include <QtCore/QHash>

#include "exports.hpp"
#include "Table.hpp"
#include "TableAttribute.hpp"
#include "Connection.hpp"




namespace db
{
	class DB_SCHEMA_API TableDL
		: public Table
	{
	public:

		typedef boost::shared_ptr<TableDL>                  Ptr;
		typedef boost::shared_ptr<const TableDL>            const_Ptr;
		typedef QVector<TableAttribute::const_Ptr>          Attributes;
		typedef QHash<QString, TableAttribute::const_Ptr>   Columns;

	private:

		QString      m_name;
		QString      m_dbName;
		Attributes   m_attributes;
		Columns      m_columns;

	public:

		TableDL(QString name, QString dbName, Attributes attributes);
		virtual ~TableDL();



		/**
		 * Tests if this table exists in the given database or not.
		 */
		bool exists(Connection::Ptr connection) const;

		/**
		 * Creates this table in the given database.
		 */
		void create(Connection::Ptr connection);

		/**
		 * Drops this table from the given database.
		 */
		void drop(Connection::Ptr connection);



		/**
		 * @returns the symbolic name of this table in the application
		 */
		virtual QString name() const;

		/**
		 * @returns the name of the table in the database
		 */
		virtual QString dbName() const;

		/**
		 * @returns the number of attributes in the database
		 */
		virtual std::size_t numAttributes() const;

		/**
		 * @returns the i-th attribute of this table
		 */
		virtual Attribute::const_Ptr attribute(std::size_t i) const;

		/**
		 * @returns the attribute with the given name
		 */
		virtual Attribute::const_Ptr attribute(QString name) const;
	};
	///////////////////////////////////////////////////////////////////////////////////////////////
}
///////////////////////////////////////////////////////////////////////////////////////////////////
